package com.okaixz.common.utils;

import java.time.LocalDateTime;

/**
 * @author 陈大专
 * @time 2025/7/4 9:35
 * @des 签到工具
 **/
public class QianDaoUtil {

    public static int qiandaoForWeek(int num){
        LocalDateTime now=LocalDateTime.now();
        int value = now.getDayOfWeek().getValue();
        int result = BitUtils.setBit1(num, value);
        return result;
    }
    /**
     * 是否签到今天
     * @param num
     * @return
     */
    public static boolean isQianDaoTodayForWeek(int num){
        LocalDateTime now=LocalDateTime.now();
        int value = now.getDayOfWeek().getValue();
        int bit = BitUtils.getBit(num, value);
        return bit==1;
    }
    /**
     * 获取一星期内连续签到天数
     * @param num
     * @return
     */
    public static int getQianDaoWeekDays(int num){
        LocalDateTime now=LocalDateTime.now();
        int value = now.getDayOfWeek().getValue();
        int count = 0;
        for (int i = value; i > 0; i--) {
            int bit = BitUtils.getBit(num, i);
            if(i!=value&&bit==0){
                //不是当前天 且未签到 结束
                break;
            }
            if(bit==1){
                count++;
            }
        }
        return count;
    }

    public static int setScore3Days(int num){
        return BitUtils.setBit1(num, 10);
    }
    public static int getScore3Days(int num){
        return BitUtils.getBit(num, 10);
    }
    public static int setScore7Days(int num){
        return BitUtils.setBit1(num, 11);
    }
    public static int getScore7Days(int num){
        return BitUtils.getBit(num, 11);
    }
}
